package com.learn.designPatterns.behavioral.memento;

/**
 * @classname:
 * @Description: Originator implemention
 * @author: yfpu
 * @Date: 2018-10-20 17:53
 */
public class CalculatorImpl implements Calculator{

    private int firstNum;
    private int secondNum;

    @Override
    public PreviousCalculatorToCareTaker backupLastCalculation() {
        // create a memento object used for restoring two numbers
        return new PreviousCalculationImpl(firstNum, secondNum);
    }

    @Override
    public void restorePreviousCalculation(PreviousCalculatorToCareTaker memento) {
        firstNum = ((PreviousCalculatorToOriginator)memento).getFirstNum();
        secondNum = ((PreviousCalculatorToOriginator)memento).getsecondNum();
    }

    @Override
    public int getCalculationResult() {
        return firstNum + secondNum;
    }

    @Override
    public void setFirstNum(int firstNum) {
        this.firstNum = firstNum;
    }

    @Override
    public void setSecondNum(int secondNum) {
        this.secondNum = secondNum;
    }
}
